var vm = new Vue({
    el: '#main',
    data: {
           versionDatas:[],
           pagination: [],
            jumpPage:'',
            versionObj:{
                systemNo:'',
                systemName:'',
                systemChargePop:'',
                systemPhone:'',
                systemPhoneType:'',
                systemUrl:'',
                systemDateUrl:'',
                serverConStr:'',
                password:'',
                fileUrl:'',
                fileName:'',
                autoFlag:'1',
                id:'',
            },
            editObj:{
                fileName:'',
                sysmaintainId:'',
                updateTime:'',
                fileUrl:'',
            },
            nowPage:1,
            rowNum:10,
            allPages:0,
            Obj:{},
            flag:true,
            tips:'',
            editID:'',
            queryData:{
                nowPage:1,
                rowNum:10,
                object:{}
            },
        listLength:'',
    },
    created: function () {
        this.Obj = sessionStorage.getItem('obj')
        this.versionObj = JSON.parse(this.Obj);
        this.getData();
    },
    methods:{
        //保存
        check_c(){
            let obj = {
                systemNo:this.versionObj.systemNo,
                systemName:this.versionObj.systemName,
                systemChargePop:this.versionObj.systemChargePop,
                systemPhone:this.versionObj.systemPhone,
                systemPhoneType:this.versionObj.systemPhoneType,
                systemDateUrl:this.versionObj.systemDateUrl,
                id:this.versionObj.id,
            }
            axios({
                method: "post",
                url: App.envUrl.backtrackUrl+"sysMaintain/updateSysMaintain",
                data: obj,
            })
            .then((data) => {
                if(data.data.code === '200'){
                    window.location.href = 'systemEnqu.html';
                }
            })
            .catch((err) => {});
        },
        radioChangez(val){
            this.versionObj.autoFlag = '1';
         },
         radioChanges(val){
             this.versionObj.autoFlag = '0'
         },
        //返回
        back(){
            window.location.href =
            "systemEnqu.html";
        },
        //列表
        getData(){
            let obj = {
                sysmaintainId:this.versionObj.id,
            }
            axios({
                method: "post",
                url: App.envUrl.backtrackUrl+"html/queryHtml",
                // url: "http://192.168.1.61:8080/slxt-web/html/queryHtml",
                data: obj,
            })
            .then((data) => {
                if(data.data.code === '200'){
                    this.versionDatas = data.data.pageCount.datas;
                    this.nowPage = data.data.pageCount.nowPage;
                    this.allPages = data.data.pageCount.allPages;
                    this.pagination = getPagination(this.nowPage,this.allPages);
                    this.listLength = data.data.pageCount.allCount;
                }else{
                    parent.showAlert(data.data.msg);
                }
            })
            .catch((err) => {});
        },
        //新增
        addBtn(){
            this.flag = true;
            $('#my-alert').modal({
                relatedTarget: this,
            });
            this.editObj.updateTime = this.getTimer();
            this.editObj.fileUrl = '';
            this.editObj.fileName = '';
            this.editObj.sysmaintainId = '';
        },
        //编辑
        gotoPage(val){
            $('#my-alert').modal({
                relatedTarget: this,
            });
            this.flag = false;
                this.editObj.fileName = val.fileName;
                this.editObj.updateTime = this.getTimer();
                this.editObj.fileUrl = val.fileUrl;
                this.editObj.sysmaintainId = val.sysmaintainId;
                this.editID = val.id;
            
        },
        confirmBtn(){
            if(this.flag === true){
                let obj ={
                    fileName:this.editObj.fileName,
                    updateTime:this.getTimer(),
                    fileUrl:this.editObj.fileUrl,
                    sysmaintainId:this.versionObj.id,
                }
                axios({
                    method: "post",
                    url: App.envUrl.backtrackUrl+"html/saveHtml",
                    // url: 'http://192.168.1.61:8080/slxt-web/html/saveHtml',
                    data: obj,
                })
                .then((data) => {
                    console.log(data,'新增');
                    this.getData();
                })
                .catch((err) => {});
            }else{
                let obj ={
                    fileName:this.editObj.fileName,
                    updateTime:this.getTimer(),
                    fileUrl:this.editObj.fileUrl,
                    sysmaintainId:this.versionObj.id,
                    id:this.editID,

                }
                axios({
                    method: "post",
                    url: App.envUrl.backtrackUrl+"html/updateHtml",
                    // url: 'http://192.168.1.61:8080/slxt-web/html/updateHtml',
                    data: obj,
                })
                .then((data) => {
                    console.log(data,'更新');
                    this.getData();
                })
                .catch((err) => {});
            }
        },
        getTimer() {
            var date = new Date();
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            var w = date.getDay();
            var w1 = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
            var h = date.getHours();
            h = h < 10 ? '0' + h : h;
            var min = date.getMinutes();
            min = min < 10 ? '0' + min : min;
            var s = date.getSeconds();
            s = s < 10 ? '0' + s : s;
          
            return y + '-' + m + '-' + d + ' ' + h + ':' + min + ':' + s;
          },
        //上传文件
        fileChange(val){
            let tem = val.target.files[0];
             this.editObj.versionCopyUrl = tem;
        },
        //分页
        selectPage(page){
            this.nowPage = page;
            this.getData();
        },
        offsetPage(offset){
            this.nowPage = this.nowPage + offset;
            this.getData();
        },
    }
});